package com.joven.shelltest.test;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.support.spring.PropertyPreFilters;
import com.joven.shelltest.dto.MessageDto;
import com.joven.shelltest.utils.HttpUtil;

import java.io.IOException;

/**
 * json打印 过滤某个字段 远程调用
 * @Author wzj
 * @Date 2023-10-12 08:39
 **/
public class OtherTest11 {
    public static void main(String[] args) throws IOException {
        MessageDto msg = new MessageDto();
        msg.setId("110");
        msg.setMessage("test msg");
        msg.setDelay(1L);

        //过滤某个字段
        JSONObject data = (JSONObject) JSONObject.toJSON(msg);
//        System.out.println(data.toString());

        JSONObject request = new JSONObject();
        request.put("data", data);
        //0预评估数据，1完整数据
        request.put("flag", "1");
        request.put("addr", "Hangzhou");
        request.put("phone", "");
        System.out.println(request.toString());
        String[] excludeProperties = {"flag", "addr"};
        PropertyPreFilters filters = new PropertyPreFilters();
        PropertyPreFilters.MySimplePropertyPreFilter excludefilter = filters.addFilter();
        excludefilter.addExcludes(excludeProperties);
        System.out.println(JSONObject.toJSONString(request, excludefilter));

        //远程调用本地工程 ToolTest工程下接口
        String testUrl = "http://192.168.29.82:9011/joven/testJson";
        String res = HttpUtil.send(testUrl, request, "utf-8");
        System.out.println(res);
    }
}
